<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>前后端交互</title>
</head>

<body>

    <!-- 
        Promise - 实例方法:
        - p.then() 得到异步任务的正确结果
        - p.catch() 获取异常信息
        - p.finally() 成功与否都灰执行(尚且不是正式标准)
     -->

    <script>
        // console.dir(Promise)
        function foo() {
            return  new Promise(function (resolve, reject) {
                setTimeout(function(){
                    // resolve(123)
                    reject('error')
                },100)
            })
        }

        /*
        foo('http://localhost:3000/data')
        .then(function(data){
            console.log(data)
        })
        .catch(function(data){
            console.log(data)
        })
        .finally(function(){
            console.log('finished')
        });
        */


        foo('http://localhost:3000/data')
        .then(function(data){
            console.log(data)
        },function(data){
            console.log(data)
        })
        .finally(function(){
            console.log('finished')
        });


    </script>

</body>

</html>